package calao.client.ui;

import java.util.Comparator;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public abstract class Link
extends Label
implements ClickListener
{
	
	public static final String STYLE = "calao-Link";
	
	boolean enabled;
	
	public Link()
	{
		addStyleName(STYLE);
		addClickListener(this);
		setEnabled(true);
	}
	
	public Link(String text)
	{
		this();
		setText(text);
	}
	
	public void emphasize()
	{
		this.addStyleName("em");
	}
	
	final public void onClick(Widget widget)
	{
		if (enabled) onClick();
	}
	
	abstract protected void onClick();
	
	public static Comparator createComparator()
	{
		return new Comparator() {
			public int compare(Object o1, Object o2) {
				return ((Link)o1).getText().compareTo(((Link)o2).getText());
			}
		};
	}
	
	public void setEnabled(boolean enabled)
	{
		this.enabled = enabled;
		if (enabled) {
			removeStyleName(Styles.DISABLED);
			addStyleName(Styles.ENABLED);
		}
		else {
			removeStyleName(Styles.ENABLED);
			addStyleName(Styles.DISABLED);
		}
	}

}
